package com.demo.structural.flyweight;

import java.util.Hashtable;

public class FlyweightFactory {
	
	private Hashtable flyweights = new Hashtable();
	
	public Flyweight getFlyWeight(String name){  
		Flyweight flyweight = (Flyweight) flyweights.get(name); 
		if(flyweight == null){
			System.out.println("对象不存在，创建对象");
			flyweight = new Flyweight(name);
			flyweights.put(name, flyweight);
		}else{
			System.out.println("对象已存在，读取对象");
		}
		return flyweight; 
	} 
	
	public int getFlyweightSize(){
		return flyweights.size();  
	} 

}
